home *** CD-ROM | disk | FTP | other *** search
-
- #include <exec/types.h>
- #include <exec/ports.h>
- #include <exec/memory.h>
- #include <libraries/commodities.h>
- #include <clib/exec_protos.h>
- #include <clib/commodities_protos.h>
- #include <clib/alib_protos.h>
-
- #include "Icon.h"
- #include "GUI.h"
- #include "CxCustom.h"
-
- #include "Cx.h"
-
- void *CxBase;
-
- BOOL HandleCxMessages(struct CxContext *cx,unsigned long signals)
- {
- struct Message *msg;
- struct GUIContext *gui=cx->UserData;
- long id;
- BOOL result=TRUE;
- if(cx)
- {
- if(signals&cx->Signals)
- {
- while(msg=GetMsg(cx->Port))
- {
- id=CxMsgID((CxMsg *)msg);
- ReplyMsg(msg);
- switch(id)
- {
- case CXCMD_DISABLE:
- ActivateCxObj(cx->CustomObject,FALSE);
- break;
- case CXCMD_ENABLE:
- ActivateCxObj(cx->CustomObject,TRUE);
- break;
- case CXCMD_UNIQUE:
- case CXCMD_APPEAR:
- gui->Show(gui);
- break;
- case CXCMD_DISAPPEAR:
- gui->Hide(gui);
- break;
- case CXCMD_KILL:
- result=FALSE;
- break;
- }
- }
- }
- }
- return(result);
- }
-
-
- BOOL Commodities_Setup()
- {
- if(!(CxBase=OpenLibrary("commodities.library",37)))
- return(FALSE);
- return(TRUE);
- }
-
-
- void Commodities_Cleanup()
- {
- if(CxBase)
- {
- CloseLibrary(CxBase);
- CxBase=NULL;
- }
- }
-
-
- struct CxContext *CreateCxContext(void *userdata)
- {
- struct CxContext *cx;
- char *hotkeystring;
- CxObj *hotkeyobj;
-
- struct NewBroker MyNewBroker =
- {
- NB_VERSION,
- "FreeMouse",
- "Fine-tune your mouse - V1.0",
- "© 1998 - Black Five SoftDesign",
- NBU_UNIQUE|NBU_NOTIFY,
- COF_SHOW_HIDE,
- 127,
- NULL
- };
-
- if(!(cx=AllocVec(sizeof(struct CxContext),MEMF_CLEAR)))
- return(NULL);
-
- cx->Dispose=DisposeCxContext;
- cx->UserData=userdata;
- cx->Handle=HandleCxMessages;
-
- cx->MouseSpeed=(GetNumericToolType("Speed",100));
- cx->MMBShift=MatchToolType("MMBShift","Yes");
- cx->ClickToFront=MatchToolType("ClickToFront","Yes");
- if(!(cx->Port=CreateMsgPort()))
- {
- cx->Dispose(cx);
- return(NULL);
- }
-
- cx->Signals=(1<<cx->Port->mp_SigBit);
-
- MyNewBroker.nb_Port=cx->Port;
- if(!(cx->Broker=CxBroker(&MyNewBroker,NULL)))
- {
- cx->Dispose(cx);
- return(NULL);
- }
-
- if(hotkeystring=GetStringToolType("CX_POPKEY"))
- {
- if(!(hotkeyobj=HotKey(hotkeystring,cx->Port,CXCMD_APPEAR)))
- {
- cx->Dispose(cx);
- return(NULL);
- }
- AttachCxObj(cx->Broker,hotkeyobj);
- }
-
- if(!(cx->CustomObject=CxCustom(&CxCustomRoutine,0)))
- {
- cx->Dispose(cx);
- return(NULL);
- }
- AttachCxObj(cx->Broker,cx->CustomObject);
-
- ActivateCxObj(cx->Broker,TRUE);
-
- return(cx);
- }
-
-
- void DisposeCxContext(struct CxContext *cx)
- {
- if(cx)
- {
- if(cx->Broker)
- {
- DeleteCxObjAll(cx->Broker);
- cx->Broker=NULL;
- }
- if(cx->Port)
- {
- DeleteMsgPort(cx->Port);
- cx->Port=NULL;
- }
- FreeVec(cx);
- }
- }
-
-